package com.ycy.exception;

import com.ycy.BaseNoListenerTest;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class A extends BaseNoListenerTest {

  @Test
  public void creat0() {
    // 创建Flowable流程引擎 Create Flowable process engine
    ProcessEngine processEngine = cfg.buildProcessEngine();
    // 获取Flowable服务 Get Flowable repositoryService
    RepositoryService repositoryService = processEngine.getRepositoryService();
    Deployment deploy = repositoryService.createDeployment().addClasspathResource("variable/abcde.bpmn20.xml").deploy();
    System.out.println(deploy.getId());
  }

  @Test
  public void createProcessInst() {
    //设置流程变量
    HashMap<String, Object> map = new HashMap<>();
    //定义的人员列表4人
    String[] v = {"shareniu1", "shareniu2"};
    map.put("assigneeList", Arrays.asList(v));
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("abcdef", map);
    System.out.println("==> 流程实例启动 实例id :" + pi.getProcessInstanceId());
  }

  @Test
  public void passBFail() {
    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().processInstanceId("35001").list();
    System.out.println("You have " + tasks.size() + " tasks:");

    HashMap<String, Object> map = new HashMap<>();
    String[] v = {"shareniu1", "shareniu2"};
    map.put("assigneeListForc", Arrays.asList(v));
    taskService.complete(tasks.get(0).getId(),map);
  }

  @Test
  public void passB() {
    TaskService taskService = processEngine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().processInstanceId("35001").list();
    System.out.println("You have " + tasks.size() + " tasks:");

    HashMap<String, Object> map = new HashMap<>();
    String[] v = {"shareniu1", "shareniu2"};
    map.put("assigneeListForc", Arrays.asList(v));
    taskService.complete(tasks.get(0).getId(),map);
  }


}
